/**
 * Created by lifeng on 2018/10/9.
 */

$(document).ready(function(){
    $("#mybutt").click(function(){
        var val = $("#kw").val();
        console.log("查询关键字:"+val);
        alert("开始查询。。。");
        window.location.href = "https://www.taobao.com";
        //$("#su").click();
    });

    $("#myGetUrl").click(function(){
        var myurl = window.location.href;
        console.log("当前url:"+myurl);
        var myval = $("#kw").val();
        var mydata = {"kw":myval,"myurl":myurl};
        console.log(mydata);
        //注入的js不能跨域,所以执行交给background.js
        chrome.extension.sendRequest(mydata, function(response) {
            console.log(response);
            alert(JSON.stringify(response));
        });
    });
});

function myview(){
    var html = "<div style='position:absolute;top:200px;right:50px;width: 200px;height: 200px;background-color:#ba7c06'>"
        +"<button id='mybutt'>点我查询</button>"
        +"<button id='myGetUrl'>采集当前输入框的信息</button>"
        +"</div>";
    $("body").append(html);
}
myview();

//$("#kw").attr("value","我是插件");

